<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/27 0027
 * Time: 14:54
 */
namespace app\admin\model;
use PHPMailer\PHPMailer\PHPMailer;

class Mailer
{
    /**发送邮件
     * @param $to:发送给谁
     * @param $title:标题
     * @param $body:内容
     * @param bool $ishtml
     * @return bool
     */
    static public function sendEmail($to,$title,$body,$ishtml=true){
        $mail  = new PHPMailer();
        try{
            $mail->SMTPDebug = 1;
            $mail->isSMTP();
            $mail->Host = config('smtp.host');
            $mail->CharSet= config('smtp.charset');
            $mail->SMTPAuth = true;
            $mail->Username = config('smtp.username');
            $mail->Password = config('smtp.password');
            $mail->SMTPSecure = config('smtp.encryption');
            $mail->Port = config('smtp.port');
            $mail->setFrom(config('smtp.username'),config('smtp.name'));
            $mail->addAddress($to);
            $mail->isHTML($ishtml);
            $mail->Subject = $title;
            $mail->Body=$body;
            $mail ->send();
            //$mail->isSMTP();
            return true;
        }catch (\Exception $e){
            return false;
        }
    }
}